package cn.lx.job;

import cn.lx.IOrderService;
import com.alipay.api.AlipayClient;
import com.alipay.api.domain.AlipayTradeQueryModel;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.response.AlipayTradeQueryResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName NoPayNotifyOrderJob
 * @Description: 超时订单处理
 * @Author: 落雪
 * @CreateDate: 2025/3/18 07:10
 * @UpdateUser: 落雪
 * @UpdateDate: 2025/3/18 07:10
 * @UpdateRemark:
 * @Version: 1.0
 */
@Slf4j
@Component
public class TimeOutCloseOrderJob {


    @Resource
    private IOrderService orderService;
    @Resource
    private AlipayClient alipayClient;

    @Scheduled(cron = "0 0/10 * * * ?")
    public void exec() {

        try {

            log.info("任务；检测超时订单");
            List<String> orderIds = orderService.queryTimeoutCloseOrderList();
            if (null == orderIds || orderIds.isEmpty()) {
                log.info("定时任务，超时30分钟订单关闭，暂无超时未支付订单 orderIds is null");
                return;
            }
            for (String orderId : orderIds) {
                boolean status = orderService.changeOrderClose(orderId);
                log.info("定时任务，超时30分钟订单关闭 orderId: {} status：{}", orderId, status);

            }

        } catch (Exception e) {
            log.error("定时任务，超时15分钟订单关闭失败", e);

        }


    }
}
